/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.config.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.constant.TableOptionConstant;
import com.icinfo.cloud.provider.common.dicenum.*;
import com.icinfo.cloud.provider.common.enums.YesOrNoEnum;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.utils.HttpUtils;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.cloud.provider.punish.approval.mapper.CaseApprovalFlowRelationMapper;
import com.icinfo.cloud.provider.punish.approval.model.CaseApprovalFlowRelation;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentLinkObjectTypeEnum;
import com.icinfo.cloud.provider.punish.config.dto.ConfigBusiParamDocumentInfoDto;
import com.icinfo.cloud.provider.punish.config.dto.ConfigBusiParamDocumentInfoPageRequest;
import com.icinfo.cloud.provider.punish.config.dto.ConfigBusiParamDocumentInfoQueryDto;
import com.icinfo.cloud.provider.punish.config.dto.GenDocumentCatalogCodeRequest;
import com.icinfo.cloud.provider.punish.config.mapper.ConfigBusiParamDocumentInfoMapper;
import com.icinfo.cloud.provider.punish.config.mapper.ConfigBusiParamMainMapper;
import com.icinfo.cloud.provider.punish.config.model.ApprovalFlowDetailInfo;
import com.icinfo.cloud.provider.punish.config.model.ConfigBusiParamDocumentInfo;
import com.icinfo.cloud.provider.punish.config.service.IConfigBusiParamDocumentInfoService;
import com.icinfo.cloud.provider.punish.config.vo.ApprovalFlowMainAndDetailInfoVo;
import com.icinfo.cloud.provider.punish.config.vo.ConfigBusiParamDocumentInfoVo;
import com.icinfo.cloud.provider.punish.config.vo.DocumentInfoVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseMainInfoService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseMainInfoVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.mybatis.pagehelper.PageHelper;
import com.icinfo.framework.tools.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述: 业务关联文书配置 config_busi_param_document_info 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2022年02月22日
 */
@Service
public class ConfigBusiParamDocumentInfoServiceImpl extends MyBatisServiceSupport implements IConfigBusiParamDocumentInfoService {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(ConfigBusiParamDocumentInfoServiceImpl.class);

    @Autowired
    private ConfigBusiParamDocumentInfoMapper configBusiParamDocumentInfoMapper;
    @Autowired
    private CaseApprovalFlowRelationMapper caseApprovalFlowRelationMapper;
    @Autowired
    private ConfigBusiParamMainMapper configBusiParamMainMapper;
    @Resource
    private ICaseMainInfoService caseMainInfoService;
    @Value("${approve.url}")
    private String url;
    @Value("${approve.api.approvalFlowDetail}")
    private String approvalFlowDetail;
    @Value("${approval.center.roleId}")
    private String approvalCenterRoleId;
    @Value("${approval.center.roleName}")
    private String approvalCenterRoleName;

    /**
     * 业务关联文书配置分页查询
     *
     * @param request
     * @return {@link List< ConfigBusiParamDocumentInfoVo>}
     * @author liyafeng
     * @date 2022/2/23
     */
    @Override
    public List<ConfigBusiParamDocumentInfoVo> getConfigBusiParamDocumentInfoVoList(ConfigBusiParamDocumentInfoPageRequest request) {
        PageHelper.startPage(request.getPageNum(), request.getLength(), request.getOrderBy());
        List<ConfigBusiParamDocumentInfoVo> configBusiParamDocumentInfoVos = configBusiParamDocumentInfoMapper.selectConfigBusiParamDocumentInfoVoList(request);
        for (ConfigBusiParamDocumentInfoVo configBusiParamDocumentInfoVo : configBusiParamDocumentInfoVos) {
            configBusiParamDocumentInfoVo.setIsApproveName(IsApproveEnum.getExplainByCode(configBusiParamDocumentInfoVo.getIsApprove()));
            configBusiParamDocumentInfoVo.setIsConfirmName(IsConfirmEnum.getExplainByCode(configBusiParamDocumentInfoVo.getIsConfirm()));
            configBusiParamDocumentInfoVo.setIsDeptSignName(IsDeptSignEnum.getExplainByCode(configBusiParamDocumentInfoVo.getIsDeptSign()));
            configBusiParamDocumentInfoVo.setIsElecSignName(IsElecSignEnum.getExplainByCode(configBusiParamDocumentInfoVo.getIsElecSign()));
            configBusiParamDocumentInfoVo.setIsSendName(IsSendEnum.getExplainByCode(configBusiParamDocumentInfoVo.getIsSend()));
            configBusiParamDocumentInfoVo.setDocumentLinkObjectTypeName(DocumentLinkObjectTypeEnum.getValueByCode(configBusiParamDocumentInfoVo.getDocumentLinkObjectType()));
        }
        return configBusiParamDocumentInfoVos;
    }

    /**
     * 业务关联文书配置保存
     *
     * @param configBusiParamDocumentInfoDto
     * @return {@link Result< String>}
     * @author liyafeng
     * @date 2022/2/23
     */
    @Override
    @Transactional(rollbackFor = {Error.class, Exception.class})
    public Result<String> saveConfigBusiParamDocumentInfoDto(ConfigBusiParamDocumentInfoDto configBusiParamDocumentInfoDto) {
        //判断文书目录编码是否存在
        Example example = new Example(ConfigBusiParamDocumentInfo.class);
        example.createCriteria().andEqualTo("documentCatalogCode", configBusiParamDocumentInfoDto.getDocumentCatalogCode()).andEqualTo("isDeleted", "0");
        List<ConfigBusiParamDocumentInfo> configBusiParamDocumentInfos = configBusiParamDocumentInfoMapper.selectByExample(example);
        if (null != configBusiParamDocumentInfos && configBusiParamDocumentInfos.size() > 0) {
            return Result.error("保存失败,文书标识已存在");
        }
        //保存案件文书审批流关系表
        if ("1".equals(configBusiParamDocumentInfoDto.getIsApprove())) {
            int num = saveCaseApprovalFlowRelation(configBusiParamDocumentInfoDto.getApproveId(), configBusiParamDocumentInfoDto.getDocumentCatalogCode());
            if (num < 1) {
                return Result.error("保存失败,保存案件文书审批流关系表失败");
            }
        }
        //保存业务关联文书配置
        ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = new ConfigBusiParamDocumentInfo();
        BeanUtils.copyProperties(configBusiParamDocumentInfoDto, configBusiParamDocumentInfo);
        configBusiParamDocumentInfo.setId(StringUtils.uuid());
        configBusiParamDocumentInfo.setCreateTime(new Date());
        configBusiParamDocumentInfo.setIsDeleted(TableOptionConstant.NOT_DELETED);
        UserDTO userDTO = UserUtil.getUserInfo();
        configBusiParamDocumentInfo.setCreateUserId(userDTO.getUserId().toString());
        configBusiParamDocumentInfo.setCreateUserName(userDTO.getRealName());
        int addNum = configBusiParamDocumentInfoMapper.insert(configBusiParamDocumentInfo);
        if (addNum > 0) {
            return Result.success("保存成功");
        } else {
            return Result.error("保存失败");
        }
    }

    /**
     * 保存案件文书审批流关系表
     *
     * @param approvelId
     * @return
     * @author liyafeng
     * @date 2022/2/24
     */
    private int saveCaseApprovalFlowRelation(String approvelId, String documentCatalogCode) {
        int num = 0;
        try {
            Map<String, Object> paramMap = new HashMap<>();
            paramMap.put("id", approvelId);
            String result = HttpUtils.doHttpPost(url + approvalFlowDetail + approvelId, paramMap);
            Map dataMap = (Map) JSONObject.parse(result);
            ApprovalFlowMainAndDetailInfoVo approvalFlowMainAndDetailInfoVo = JSONObject.parseObject(dataMap.get("data").toString(), ApprovalFlowMainAndDetailInfoVo.class);
            List<ApprovalFlowDetailInfo> approvalFlowDetailInfos = approvalFlowMainAndDetailInfoVo.getApprovalFlowDetailInfoList();
            for (ApprovalFlowDetailInfo approvalFlowDetailInfo : approvalFlowDetailInfos) {
                CaseApprovalFlowRelation caseApprovalFlowRelation = new CaseApprovalFlowRelation();
                caseApprovalFlowRelation.setId(StringUtils.uuid());
                caseApprovalFlowRelation.setApprovalFlowId(approvalFlowDetailInfo.getFlowid());
                caseApprovalFlowRelation.setApprovalFlowVerson(approvalFlowDetailInfo.getFlowVerson());
                caseApprovalFlowRelation.setApprovalLevel(approvalFlowDetailInfo.getApprovalLevel());
                caseApprovalFlowRelation.setApprovalOpinionType(approvalFlowDetailInfo.getApprovalOpinionType());
                caseApprovalFlowRelation.setApprovalOrderNum(approvalFlowDetailInfo.getApprovalOrderNum());
                caseApprovalFlowRelation.setApprovalRole(approvalFlowDetailInfo.getApprovalRole());
                caseApprovalFlowRelation.setApprovalRoleName(approvalFlowDetailInfo.getApprovalRoleName());
                caseApprovalFlowRelation.setApprovalScope(approvalFlowDetailInfo.getApprovalScope());
                caseApprovalFlowRelation.setApprovalTerm(approvalFlowDetailInfo.getApprovalTerm());
                caseApprovalFlowRelation.setDocumentCatalogCode(documentCatalogCode);
                caseApprovalFlowRelation.setIsNowVersion("1");
                //判断角色是否为联合法制审核角色
                if (approvalCenterRoleId.equals(approvalFlowDetailInfo.getApprovalRole())) {
                    caseApprovalFlowRelation.setIsApprovalCenter("1");
                } else {
                    caseApprovalFlowRelation.setIsApprovalCenter("0");
                }
                num = caseApprovalFlowRelationMapper.insert(caseApprovalFlowRelation);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return num;
    }

    /**
     * 业务关联文书配置修改
     *
     * @param configBusiParamDocumentInfoDto
     * @return {@link Result< String>}
     * @author liyafeng
     * @date 2022/2/23
     */
    @Override
    @Transactional(rollbackFor = {Error.class, Exception.class})
    public Result<String> editConfigBusiParamDocumentInfoDto(ConfigBusiParamDocumentInfoDto configBusiParamDocumentInfoDto) {
        //判断approvalId是否变化
        ConfigBusiParamDocumentInfo oldConfigBusiParamDocumentInfo = configBusiParamDocumentInfoMapper.selectByPrimaryKey(configBusiParamDocumentInfoDto.getId());
        String oldApprovalId = oldConfigBusiParamDocumentInfo.getApproveId();
        if ("1".equals(configBusiParamDocumentInfoDto.getIsApprove()) && !configBusiParamDocumentInfoDto.getApproveId().equals(oldApprovalId)) {
            //修改案件文书审批流关系表
            int num = editCaseApprovalFlowRelation(configBusiParamDocumentInfoDto.getApproveId(), configBusiParamDocumentInfoDto.getDocumentCatalogCode());
            if (num < 1) {
                return Result.error("修改失败,修改案件文书审批流关系表失败");
            }
        }
        ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = new ConfigBusiParamDocumentInfo();
        BeanUtils.copyProperties(configBusiParamDocumentInfoDto, configBusiParamDocumentInfo);
        int editNum = configBusiParamDocumentInfoMapper.updateByPrimaryKeySelective(configBusiParamDocumentInfo);
        if (editNum > 0) {
            return Result.success("修改成功");
        } else {
            return Result.error("修改失败");
        }
    }

    /**
     * 修改案件文书审批流关系表
     *
     * @param approveId
     * @param documentCatalogCode
     * @return {@link int}
     * @author liyafeng
     * @date 2022/2/24
     */
    private int editCaseApprovalFlowRelation(String approveId, String documentCatalogCode) {
        int num = 0;
        //将documentCatalogCode对应的审批流设置为非当前版本
        caseApprovalFlowRelationMapper.updateCaseApprovalFlowRelationByDocumentCatalogCode(documentCatalogCode);
        //判断对应的approveId、documentCatalogCode是否在relation表中存在
        Example example = new Example(CaseApprovalFlowRelation.class);
        example.createCriteria().andEqualTo("approvalFlowId", approveId).andEqualTo("documentCatalogCode", documentCatalogCode);
        List<CaseApprovalFlowRelation> caseApprovalFlowRelations = caseApprovalFlowRelationMapper.selectByExample(example);
        if (null != caseApprovalFlowRelations && caseApprovalFlowRelations.size() > 0) {
            //存在，则更新对应的数据为当前使用版本
            Map<String, Object> paramMap = new HashMap<>();
            paramMap.put("approvalFlowId", approveId);
            paramMap.put("documentCatalogCode", documentCatalogCode);
            num = caseApprovalFlowRelationMapper.updateCaseApprovalFlowRelationByMap(paramMap);
        } else {
            //不存在，则新增为当前版本
            num = saveCaseApprovalFlowRelation(approveId, documentCatalogCode);
        }
        return num;
    }

    /**
     * 业务关联文书配置 删除
     *
     * @param id
     * @return {@link Result< String>}
     * @author liyafeng
     * @date 2022/2/23
     */
    @Override
    public Result<String> rmById(String id) {
        ConfigBusiParamDocumentInfo updateConfigBusiParamDocumentInfo = new ConfigBusiParamDocumentInfo();
        updateConfigBusiParamDocumentInfo.setId(id);
        updateConfigBusiParamDocumentInfo.setIsDeleted(Constant.STRING_1);
        int editNum = configBusiParamDocumentInfoMapper.updateByPrimaryKeySelective(updateConfigBusiParamDocumentInfo);
        if (editNum > 0) {
            return Result.success("删除成功");
        } else {
            return Result.error("删除失败");
        }
    }

    /**
     * 根据主键获取详情
     *
     * @param id
     * @return {@link Result< ConfigBusiParamDocumentInfo>}
     * @author liyafeng
     * @date 2022/2/23
     */
    @Override
    public Result<ConfigBusiParamDocumentInfo> getDetailById(String id) {
        ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfoMapper.selectByPrimaryKey(id);
        return Result.success(configBusiParamDocumentInfo);
    }

    /**
     * 根据文书目录编码获取详情
     *
     * @param documentCatalogCode
     * @return {@link ConfigBusiParamDocumentInfo}
     * @author liyafeng
     * @date 2022/2/25
     */
    @Override
    public ConfigBusiParamDocumentInfo getDetailByDocumentCatalogCode(String documentCatalogCode) {
        Example example = new Example(ConfigBusiParamDocumentInfo.class);
        example.createCriteria().andEqualTo("documentCatalogCode", documentCatalogCode).andEqualTo("isDeleted", "0");
        List<ConfigBusiParamDocumentInfo> configBusiParamDocumentInfos = configBusiParamDocumentInfoMapper.selectByExample(example);
        ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = new ConfigBusiParamDocumentInfo();
        if (null != configBusiParamDocumentInfos && configBusiParamDocumentInfos.size() > 0) {
            configBusiParamDocumentInfo = configBusiParamDocumentInfos.get(0);
        } else {
            throw new BusinessException("未匹配到业务关联文书配置记录");
        }
        return configBusiParamDocumentInfo;
    }

    /**
     * 生成文书目录编码
     *
     * @param request
     * @return {@link Result< String>}
     * @author liyafeng
     * @date 2022/2/25
     */
    @Override
    public Result<String> genDocumentCatalogCode(GenDocumentCatalogCodeRequest request) {
        //String busiParamId=request.getBusiParamId();
       /* String documentKindCode=request.getDocumentKindCode();
        String documentCatalogCode=documentKindCode+"-0001";
        //查询最大的编码
        String maxDocumentCatalogCode=configBusiParamDocumentInfoMapper.selectMaxDocumentCatalogCodeByKindCode(documentKindCode);
        if(StringUtils.isNotBlank(maxDocumentCatalogCode)){
            int codeNum = Integer.parseInt(maxDocumentCatalogCode.substring(maxDocumentCatalogCode.length()-4));
            String str = "0000" + String.valueOf(codeNum + 1);
            documentCatalogCode=documentKindCode+"-"+str.substring(str.length()-4);
        }*/
        String busiParamId = request.getBusiParamId();
        String documentKindCode = request.getDocumentKindCode();
        /*ConfigBusiParamMain configBusiParamMain=configBusiParamMainMapper.selectByPrimaryKey(busiParamId);
        String applyAreaCode=configBusiParamMain.getApplyAreaCode();
        String applyFieldCode=configBusiParamMain.getApplyFieldCode();
        String documentCatalogCode=applyFieldCode+applyAreaCode+documentKindCode+StringUtils.uuid().substring(1,6);*/
        String documentCatalogCode = documentKindCode + StringUtils.uuid().substring(1, 6);
        return Result.success(documentCatalogCode);
    }

    /**
     * 根据参数配置id获取所有的参数配置下的文书目录
     *
     * @param busiParamId
     * @return {@link List< DocumentInfoVo>}
     * @author liyafeng
     * @date 2022/3/1
     */
    @Override
    public List<DocumentInfoVo> getDocumentInfoByBusiParamId(String busiParamId) {
        List<DocumentInfoVo> documentInfoVos = configBusiParamDocumentInfoMapper.selectDocumentInfoByBusiParamId(busiParamId);
        return documentInfoVos;
    }

    @Override
    public ConfigBusiParamDocumentInfo getDocumentInfoByDocumentKindCode(String busiParamId, String documentKindCode) {
        Example example = new Example(ConfigBusiParamDocumentInfo.class);
        if(StringUtils.isNotBlank(busiParamId)){
            example.createCriteria().andEqualTo("busiParamId", busiParamId)
                    .andEqualTo("documentKindCode", documentKindCode);
        }else{
            example.createCriteria().andEqualTo("documentKindCode", documentKindCode);
        }
        List<ConfigBusiParamDocumentInfo> configBusiParamMainList = configBusiParamDocumentInfoMapper.selectByExample(example);
        if (ObjectUtil.isNotEmpty(configBusiParamMainList)){
            return configBusiParamMainList.get(0);
        }
        return null;
    }
    @Override
    public List<ConfigBusiParamDocumentInfoVo> getCConfigBusiParamDocumentInfoByGroupList(ConfigBusiParamDocumentInfoQueryDto queryDto) {
        List<ConfigBusiParamDocumentInfoVo> configBusiParamDocumentInfoVos = configBusiParamDocumentInfoMapper.selectConfigBusiParamDocumentInfoList(queryDto);
        return configBusiParamDocumentInfoVos;
    }

    /**
     * 描述：根据文书目录编码等信息查询文书配置信息
     *
     * @param caseId              案件id
     * @param caseMainInfo        {@link CaseMainInfoVo}
     * @param documentCatalogCode 文书目录编码
     * @return {@link List<ConfigBusiParamDocumentInfo>} 文书配置信息列表
     * @author xiangyuyu
     * @date 2022/8/2
     * @since 1.3.2
     */
    @Override
    public List<ConfigBusiParamDocumentInfo> getDocumentConfigInfoByDocumentCatalogCode(String caseId, CaseMainInfoVo caseMainInfo, String documentCatalogCode) {
        List<ConfigBusiParamDocumentInfo> list = null;
        if (ObjectUtils.isEmpty(caseMainInfo)) {
            //获取案件主干信息
            if (!ObjectUtils.isEmpty(caseId)) {
                caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
            }
            if (ObjectUtils.isEmpty(documentCatalogCode)) {
                return list;
            }
        }
        if (!ObjectUtils.isEmpty(caseMainInfo)) {
            String busiParamId = caseMainInfo.getBusiParamId();
            Example query = new Example(ConfigBusiParamDocumentInfo.class);
            query.createCriteria().andEqualTo("documentCatalogCode", documentCatalogCode)
                    .andEqualTo("busiParamId", busiParamId)
                    .andEqualTo("isDeleted", YesOrNoEnum.NO.getCode());
            list = configBusiParamDocumentInfoMapper.selectByExample(query);
        }
        return list;
    }

    /**
     * 描述：根据文书种类编码等信息查询文书配置信息
     *
     * @param caseId           案件id
     * @param caseMainInfo     {@link CaseMainInfoVo}
     * @param documentKindCode 文书种类编码
     * @return {@link List<ConfigBusiParamDocumentInfo>} 文书配置信息列表
     * @author xiangyuyu
     * @date 2022/8/2
     * @since 1.3.2
     */
    @Override
    public List<ConfigBusiParamDocumentInfo> getDocumentConfigInfoByDocumentKindCode(String caseId, CaseMainInfoVo caseMainInfo, String documentKindCode) {
        List<ConfigBusiParamDocumentInfo> list = null;
        if (ObjectUtils.isEmpty(caseMainInfo)) {
            //获取案件主干信息
            if (!ObjectUtils.isEmpty(caseId)) {
                caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
            }
            if (ObjectUtils.isEmpty(documentKindCode)) {
                return list;
            }
        }
        if (!ObjectUtils.isEmpty(caseMainInfo)) {
            String busiParamId = caseMainInfo.getBusiParamId();
            Example query = new Example(ConfigBusiParamDocumentInfo.class);
            query.createCriteria().andEqualTo("documentKindCode", documentKindCode)
                    .andEqualTo("busiParamId", busiParamId)
                    .andEqualTo("isDeleted", YesOrNoEnum.NO.getCode());
            list = configBusiParamDocumentInfoMapper.selectByExample(query);
        }
        //TODO:目前执行情况记录，是会有多条，查出来的文书目录编码是不同的。
        return list;
    }
    /**
     * 根据参数id文书目录编码获取文书配置信息
     * @author liyafeng
     * @date 2022/8/8
      * @param busiParamId
     * @param documentCatalogCode
     * @return {@link ConfigBusiParamDocumentInfo}
     */
    @Override
    public ConfigBusiParamDocumentInfo getConfigBusiParamDocumentInfoByBusiParamIdAndCode(String busiParamId, String documentCatalogCode) {
        Example example = new Example(ConfigBusiParamDocumentInfo.class);
        example.createCriteria().andEqualTo("documentCatalogCode", documentCatalogCode).andEqualTo("busiParamId",busiParamId).andEqualTo("isDeleted", "0");
        List<ConfigBusiParamDocumentInfo> configBusiParamDocumentInfos = configBusiParamDocumentInfoMapper.selectByExample(example);
        ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = new ConfigBusiParamDocumentInfo();
        if (null != configBusiParamDocumentInfos && configBusiParamDocumentInfos.size() > 0) {
            configBusiParamDocumentInfo = configBusiParamDocumentInfos.get(0);
        } else {
            throw new BusinessException("未匹配到业务关联文书配置记录");
        }
        return configBusiParamDocumentInfo;
    }


    /**
     * 根据需送达文书目录编码获取送达回证配置详情
     *
     * @param sentDocumentCatalogCode
     * @return {@link ConfigBusiParamDocumentInfo}
     * @author zhengqiang
     * @date 2022/10/26
     */
    @Override
    public ConfigBusiParamDocumentInfo getSDHZDetailBySentDocumentCatalogCode(String sentDocumentCatalogCode) {
        Example example = new Example(ConfigBusiParamDocumentInfo.class);
        example.createCriteria().andEqualTo("matchSentDocumentCatalogCode", sentDocumentCatalogCode).andEqualTo("isDeleted", "0");
        List<ConfigBusiParamDocumentInfo> configBusiParamDocumentInfos = configBusiParamDocumentInfoMapper.selectByExample(example);
        if (null != configBusiParamDocumentInfos && configBusiParamDocumentInfos.size() > 0) {
            return configBusiParamDocumentInfos.get(0);
        } else {
            throw new BusinessException("未匹配到关联的送达回证文书配置记录");
        }
    }

    @Override
    public ConfigBusiParamDocumentInfo getFastCaseDocumentInfoByDocumentKindCode(String busiParamId, String documentKindCode, String isFastCase) {
        Example example = new Example(ConfigBusiParamDocumentInfo.class);
        Example.Criteria criteria = example.createCriteria();
        if(StringUtils.isNotBlank(busiParamId)){
            criteria.andEqualTo("busiParamId", busiParamId);

        }
        if(StringUtils.isNotBlank(isFastCase)){
            criteria.andEqualTo("isFastCase", isFastCase);

        }
        criteria.andEqualTo("documentKindCode", documentKindCode);
        List<ConfigBusiParamDocumentInfo> configBusiParamMainList = configBusiParamDocumentInfoMapper.selectByExample(example);
        if (ObjectUtil.isNotEmpty(configBusiParamMainList)){
            return configBusiParamMainList.get(0);
        }
        return null;
    }
}
